/*
 * player.h
 *
 *  Created on: Jul 11, 2011
 *      Author: alemao
 */

#ifndef PLAYER_H_
#define PLAYER_H_

#include "teams.h"

#define PLAYERNAME_SIZE		20
#define TEAMNAME_SIZE		20
#define ROUNDS_TOTAL		20

enum player_class{
	CLASSLESS,
	ATACANTE,
	LATERAL,
	GOLEIRO,
	MEIA,
	ZAGUEIRO,
	TECNICO,
	CLASS_TOTAL
};

#define JOGOU					statistic.played
#define JOGOU_CONTRA			statistic.played_against
#define JOGOU_EM_CASA			statistic.home
#define MEDIA					statistic.average
#define PONTUACAO				statistic.points
#define PRECO					statistic.price
#define FALTAS_SOFRIDAS			statistic.fs
#define PASSES_ERRADOS			statistic.pe
#define ASSISTENCIAS			statistic.a
#define FINALIZACOES_NA_TRAVE	statistic.ft
#define FINALIZACOES_DEFENDIDAS	statistic.fd
#define FINALIZACOES_PARA_FORA	statistic.ff
#define	GOLS					statistic.g
#define IMPEDIMENTOS			statistic.i
#define PENALTIS_PERDIDOS		statistic.pd
#define ROUBADAS_DE_BOLA		statistic.rb
#define FALTAS_COMETIDAS		statistic.fc
#define GOLS_CONTRA				statistic.gc
#define CARTOES_AMARELOS		statistic.ca
#define CARTOES_VERMELHOS		statistic.cv
#define JOGOS_SEM_SOFRER_GOLS	statistic.sg
#define DEFESAS_DIFICEIS		statistic.dd
#define DEFESAS_DE_PENALTIS		statistic.dp
#define GOLS_SOFRIDOS			statistic.gs


typedef struct _player player;
typedef union _statistics player_statistcs;
typedef player **playerlist;
struct _team{
	char teamname[TEAMNAME_SIZE];
	int value;
};

struct _player{
	char *name;
	int class;
	int team;
	int start_price;
	player_statistcs *statistics[ROUNDS_TOTAL];
};

#define STATISTICS_ARRAY_SIZE		24
#define STATISTICS_OFFSET			6
union _statistics{
	struct {
		int played;
		int played_against;
		int home;
		int average;
		int points;
		int price;
		int fs, pe, a, ft, fd, ff, g, i, pp;
		int rb, fc, gc, ca, cv, sg, dd, dp, gs;
	}statistic;
	int stats[STATISTICS_ARRAY_SIZE];
};

/* player.c */
extern player *libplayer_parseplayer(char *player_stats);
extern player_statistcs *libplayer_parsestatistics(char *player_stats);
extern void libplayer_freeplayer(player *Player);
extern void libplayer_freestatistics(player_statistcs *Statistics);
extern int libplayer_getteamname(char *teamname, int team, size_t size);
extern int libplayer_getclassname(char *classname, int class, size_t size);
extern int libplayer_cleanstatistics(player *Player);

/* playerlist.c*/
extern player **libplayer_createlist(void);
extern int libplayer_appendtolist(player ***List, player *Player);
extern int libplayer_findplayer(player **List, player *Player);
void libplayer_freelist(player **List);

#endif /* PLAYER_H_ */
